package com.s3_boot_mp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.s3_boot_mp.mapper.UserMapper;
import com.s3_boot_mp.pojo.SysUser;
import com.s3_boot_mp.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    UserMapper userMapper;

    QueryWrapper queryWrapper;

    public UserServiceImpl() {
        queryWrapper =new QueryWrapper();
    }

    @Override
    public SysUser login(String userName, String password) {
        queryWrapper=new QueryWrapper();

        queryWrapper.allEq(new HashMap<String,String>(){
            {
                put("usr_name",userName);
                put("usr_password",password);
            }

        });
        List<SysUser> list =userMapper.selectList(queryWrapper);
        if (null!=list && list.size()>0)
        {
            return list.get(0);
        }else{
            return null;
        }
    }

    @Override
    public int addUser(SysUser user) {
        return userMapper.insert(user);
    }

    @Override
    public int delUser(Long usrId) {
        return userMapper.deleteById(usrId);
    }

    @Override
    public int updateUser(SysUser user) {
        return userMapper.updateById(user);
    }

    @Override
    public SysUser getUser(Long usrId) {
        return userMapper.selectById(usrId);
    }

    @Override
    public List<SysUser> findAllUsers() {
        return userMapper.selectList(null);
    }
}
